package jdbc2;

import org.junit.Test;

import java.sql.*;

public class jdbcLearn {
    @Test
    public void isAdmin() throws SQLException {
        String url="jdbc:mysql://localhost:3306/tbl_student?useSSL=false&serverTimezone=UTC";
        String username="root";
        String password="123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        String name="ee";
        String pwd="335";
        String sql="select*from stu_score where username=?and password=?";
        PreparedStatement preparedStatement=connection.prepareStatement(sql);
        preparedStatement.setString(1,name);
        preparedStatement.setString(2,pwd);
        ResultSet resultSet = preparedStatement.executeQuery();
        if(resultSet.next())
        {
            System.out.println("登陆成功");
        }else{
            System.out.println("非法管理员");
        }
    }
    @Test
    public void insert() throws SQLException {
        String url="jdbc:mysql://localhost:3306/tbl_student?useSSL=false&serverTimezone=UTC";
        String username="root";
        String password="123456";
        Connection connection = DriverManager.getConnection(url, username, password);
        String sql="insert into stu_score values(null,?,?)";
        PreparedStatement prestatement = connection.prepareStatement(sql);
        prestatement.setString(1,"1");
        prestatement.setString(2,"123");
        int i = prestatement.executeUpdate();
        System.out.println("向数据库表中添加了"+i+"行数据");
    }

}
